const Mock = require("mockjs");

const Random = Mock.Random;

let Result = {
  code: 200,
  msg: "操作成功",
  data: null
};

Mock.mock("/kaptcha", "get", () => {
  Result.data = {
    token: Random.string(32),
    codeImg: Random.dataImage("120x40", "P7n5w")
  };

  return Result;
});

Mock.mock(RegExp("/login*"), "post", () => {
  //   Result.code = 400;
  //   Result.msg = "验证码错误";
  return Result;
});

Mock.mock("/sys/getUserInfo", "get", () => {
  //   Result.code = 400;
  //   Result.msg = "验证码错误";
  Result.data = {
    id: "1",
    username: "张斌",
    portrait:
      "https://img0.baidu.com/it/u=1531038383,3455172191&fm=26&fmt=auto&gp=0.jpg"
  };
  return Result;
});

Mock.mock("/logout", "get", () => {
  //   Result.code = 400;
  //   Result.msg = "验证码错误";
  return Result;
});

Mock.mock("/sys/menu/anv", "get", () => {
  // Result.code = 200;
  // Result.msg = "sdfasdfsaf";
  //导航菜单信息和权限信息
  let nav = [
    {
      name: "SysMange",
      title: "系统管理",
      icon: "el-icon-setting",
      path: "",
      component: "",
      children: [
        {
          name: "SysUser",
          title: "用户管理",
          icon: "el-icon-user",
          path: "/sys/users",
          component: "sys/User",
          children: []
        },
        {
          name: "SysRole",
          title: "角色管理",
          icon: "el-icon-user-solid",
          path: "/sys/roles",
          component: "sys/Role",
          children: []
        },
        {
          name: "SysMenu",
          title: "菜单管理",
          icon: "el-icon-menu",
          path: "/sys/menus",
          component: "sys/Menu",
          children: []
        }
      ]
    }
  ];
  let authoritys = ["sys:user:list", "sys:user:save"];
  Result.data = {
    nav: nav,
    authoritys: authoritys
  };
  return Result;
});

///菜单管理
Mock.mock(RegExp("/sys/menu/list*"), "get", () => {
  let menus = [
    {
      id: 1,
      created: "2016-05-02T18:58:18",
      updated: "2016-05-02T18:58:18",
      statu: 1,
      parentId: 0,
      name: "系统管理",
      path: "",
      perms: "sys:manage",
      component: "",
      type: 0,
      icon: "el-icon-s-operation",
      ordernum: 1,
      children: [
        {
          id: 2,
          created: "2016-05-02T18:58:18",
          updated: "2016-05-02T18:58:18",
          statu: 1,
          parentId: 1,
          name: "用户管理",
          path: "/sys/users",
          perms: "sys:user:list",
          component: "sys/User",
          type: 1,
          icon: "el-icon-s-custom",
          ordernum: 1,
          children: [
            {
              id: 9,
              created: "2021-01-17T21:48:32",
              updated: null,
              statu: 1,
              parentId: 2,
              name: "添加用户",
              path: null,
              perms: "sys:user:save",
              component: null,
              type: 2,
              icon: null,
              ordernum: 1,
              children: []
            },
            {
              id: 10,
              created: "2021-01-17T21:49:03",
              updated: "2021-01-17T21:53:04",
              statu: 1,
              parentId: 2,
              name: "修改用户",
              path: null,
              perms: "sys:user:update",
              component: null,
              type: 2,
              icon: null,
              ordernum: 2,
              children: []
            },
            {
              id: 11,
              created: "2021-01-17T21:49:21",
              updated: null,
              statu: 1,
              parentId: 2,
              name: "删除用户",
              path: null,
              perms: "sys:user:delete",
              component: null,
              type: 2,
              icon: null,
              ordernum: 3,
              children: []
            },
            {
              id: 12,
              created: "2021-01-17T21:49:58",
              updated: null,
              statu: 1,
              parentId: 2,
              name: "分配角色",
              path: null,
              perms: "sys:user:role",
              component: null,
              type: 2,
              icon: null,
              ordernum: 4,
              children: []
            },
            {
              id: 13,
              created: "2021-01-17T21:50:36",
              updated: null,
              statu: 1,
              parentId: 2,
              name: "重置密码",
              path: null,
              perms: "sys:user:repass",
              component: null,
              type: 2,
              icon: null,
              ordernum: 5,
              children: []
            }
          ]
        },
        {
          id: 3,
          created: "2016-05-02T18:58:18",
          updated: "2016-05-02T18:58:18",
          statu: 1,
          parentId: 1,
          name: "角色管理",
          path: "/sys/roles",
          perms: "sys:role:list",
          component: "sys/Role",
          type: 1,
          icon: "el-icon-rank",
          ordernum: 2,
          children: []
        }
      ]
    },
    {
      id: 5,
      created: "2021-01-15T19:06:11",
      updated: null,
      statu: 1,
      parentId: 0,
      name: "系统工具",
      path: "",
      perms: "sys:tools",
      component: null,
      type: 0,
      icon: "el-icon-s-tools",
      ordernum: 2,
      children: [
        {
          id: 6,
          created: "2021-01-15T19:07:18",
          updated: "2021-01-18T16:32:13",
          statu: 1,
          parentId: 5,
          name: "数字字典",
          path: "/sys/dicts",
          perms: "sys:dict:list",
          component: "sys/Dict",
          type: 1,
          icon: "el-icon-s-order",
          ordernum: 1,
          children: []
        }
      ]
    }
  ];
  //   Result.code = 400;
  //   Result.msg = "验证码错误";
  Result.data = menus;
  return Result;
});

Mock.mock(RegExp("/sys/menu/info/*"), "get", () => {
  Result.data = {
    id: 3,
    statu: 1,
    parentId: 1,
    name: "角色管理",
    path: "/sys/roles",
    perms: "sys:role:list",
    component: "sys/Role",
    type: 1,
    icon: "el-icon-rank",
    orderNum: 2,
    children: []
  };

  return Result;
});

Mock.mock(RegExp("/sys/role/info/*"), "get", () => {
  Result.data = {
    id: 6,
    created: "2021-01-16T13:29:03",
    updated: "2021-01-17T15:50:45",
    statu: 1,
    name: "超级管理员",
    code: "admin",
    remark: "系统默认最高权限，不可以编辑和任意修改",
    menuIds: [3]
  };

  return Result;
});

Mock.mock("/sys/menu/update", "get", () => {
  return Result;
});

Mock.mock("/sys/menu/delete/", "post", () => {
  return Result;
});

Mock.mock("/sys/role/save", "get", () => {
  return Result;
});

Mock.mock(RegExp("/sys/role/*"), "post", () => {
  return Result;
});

Mock.mock(RegExp("/sys/role/list*"), "get", () => {
  Result.data = {
    records: [
      {
        id: 3,
        created: "2021-01-04T10:09:14",
        updated: "2021-01-30T08:19:52",
        statu: 1,
        name: "普通用户",
        code: "normal",
        remark: "只有基本查看功能",
        menuIds: []
      },
      {
        id: 6,
        created: "2021-01-16T13:29:03",
        updated: "2021-01-17T15:50:45",
        statu: 1,
        name: "超级管理员",
        code: "admin",
        remark: "系统默认最高权限，不可以编辑和任意修改",
        menuIds: []
      }
    ],
    total: 2,
    size: 10,
    current: 1,
    orders: [],
    optimizeCountSql: true,
    hitCount: false,
    countId: null,
    maxLimit: null,
    searchCount: true,
    pages: 1
  };

  return Result;
});

//////////////// 用户管理 ////////////////

Mock.mock(RegExp("/sys/user/list*"), "get", () => {
  Result.data = {
    records: [
      {
        id: 1,
        created: "2021-01-12T22:13:53",
        updated: "2021-01-16T16:57:32",
        statu: 1,
        username: "admin",
        password:
          "$2a$10$R7zegeWzOXPw871CmNuJ6upC0v8D373GuLuTw8jn6NET4BkPRZfgK",
        avatar:
          "https://image-1300566513.cos.ap-guangzhou.myqcloud.com/upload/images/5a9f48118166308daba8b6da7e466aab.jpg",
        email: "123@qq.com",
        city: "广州",
        lastLogin: "2020-12-30T08:38:37",
        roles: [
          {
            id: 6,
            created: "2021-01-16T13:29:03",
            updated: "2021-01-17T15:50:45",
            statu: 1,
            name: "超级管理员",
            code: "admin",
            remark: "系统默认最高权限，不可以编辑和任意修改",
            menuIds: []
          },
          {
            id: 3,
            created: "2021-01-04T10:09:14",
            updated: "2021-01-30T08:19:52",
            statu: 1,
            name: "普通用户",
            code: "normal",
            remark: "只有基本查看功能",
            menuIds: []
          }
        ]
      },
      {
        id: 2,
        created: "2021-01-30T08:20:22",
        updated: "2021-01-30T08:55:57",
        statu: 1,
        username: "test",
        password:
          "$2a$10$0ilP4ZD1kLugYwLCs4pmb.ZT9cFqzOZTNaMiHxrBnVIQUGUwEvBIO",
        avatar:
          "https://image-1300566513.cos.ap-guangzhou.myqcloud.com/upload/images/5a9f48118166308daba8b6da7e466aab.jpg",
        email: "test@qq.com",
        city: null,
        lastLogin: null,
        roles: [
          {
            id: 3,
            created: "2021-01-04T10:09:14",
            updated: "2021-01-30T08:19:52",
            statu: 1,
            name: "普通用户",
            code: "normal",
            remark: "只有基本查看功能",
            menuIds: []
          }
        ]
      }
    ],
    total: 2,
    size: 10,
    current: 1,
    orders: [],
    optimizeCountSql: true,
    hitCount: false,
    countId: null,
    maxLimit: null,
    searchCount: true,
    pages: 1
  };

  return Result;
});

Mock.mock(RegExp("/sys/user/*"), "post", () => {
  return Result;
});

Mock.mock(RegExp("/sys/user/info/*"), "get", () => {
  Result.data = {
    id: 2,
    created: "2021-01-30T08:20:22",
    updated: "2021-01-30T08:55:57",
    statu: 1,
    username: "test",
    password: "$2a$10$0ilP4ZD1kLugYwLCs4pmb.ZT9cFqzOZTNaMiHxrBnVIQUGUwEvBIO",
    avatar:
      "https://image-1300566513.cos.ap-guangzhou.myqcloud.com/upload/images/5a9f48118166308daba8b6da7e466aab.jpg",
    email: "test@qq.com",
    city: null,
    lastLogin: null,
    roles: [3, 6]
  };
  return Result;
});
